// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: donggu

#pragma once

#include <utility>
#include <optional>
#include <algorithm>
#include <string>
#include <vector>

#include <toml.hpp>

#include "coin2/base/time.h"

struct WsRateLimit {
  std::optional<int> max_subscription;
  std::optional<std::pair<int64_t, int64_t>> connection;
  std::optional<std::pair<int64_t, int64_t>> subscription;
  std::optional<std::pair<int64_t, int64_t>> command;

  static WsRateLimit ParseToml(const toml::table& table) {
    WsRateLimit config;
    if (table.find("connection") != table.end()) {
      config.connection = RateFromIso8601(table.at("connection").as_string());
    }
    if (table.find("subscription") != table.end()) {
      config.subscription = RateFromIso8601(table.at("subscription").as_string());
    }
    if (table.find("command") != table.end()) {
      config.command = RateFromIso8601(table.at("command").as_string());
    }
    if (table.find("max_subscription") != table.end()) {
      config.max_subscription = table.at("max_subscription").as_integer();
    }
    return config;
  }
};

struct WsUrl {
  std::string host;
  std::string port;
  std::string path;
  std::string method;
  std::string proxy;
  std::string name;
  std::string bind_ip;
  std::string request;
  WsRateLimit unauthorized_limit;
  bool disable_ssl;
  std::vector<std::string> channels;
  bool wrap_response;
  bool support_ping_frame;
};
